#include "head.h"


// 初始化用来监听端口建立握手的socket对象
int initSocket(int *socket_fd, char *ip, char *port){

    *socket_fd = socket(AF_INET, SOCK_STREAM, 0);
    // 解除TIME_WAIT等待时:导致端口占用问题
    int reuse = 1;
    setsockopt(*socket_fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));

    struct sockaddr_in sockaddr;
    sockaddr.sin_family = AF_INET;
    sockaddr.sin_port = htons(atoi(port));
    sockaddr.sin_addr.s_addr = inet_addr(ip);
    bind(*socket_fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr));

    int ret = listen(*socket_fd, 10);
    
    return 0;
}


